//
//  NoticeDesViewController.swift
//  jiaoyi
//
//  Created by wjk on 2018/11/6.
//  Copyright © 2018 wjk. All rights reserved.
//

import UIKit
import Alamofire

class NoticeDesViewController: UIViewController {

    @IBOutlet weak var labelTitle: UILabel!
    @IBOutlet weak var labelDate: UILabel!
    @IBOutlet weak var labelContent: UILabel!
    @IBOutlet weak var btnFile: UIButton!
    @IBOutlet weak var labelAddress: UILabel!
    
    var msgId:String!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "消息详情"
        
        NetWorkRequest(.message_id(id: self.msgId)) { (res) -> (Void) in
            let jd = jsonFormater(data: res)
            if jd["code"].stringValue == "000000" {
                
                self.labelContent.attributedText = try! NSAttributedString.init(data: (jd["data"].dictionaryValue["content"]?.stringValue.data(using: String.Encoding.unicode))!, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
                self.labelDate.text = jd["data"].dictionaryValue["created_at"]?.stringValue
                self.labelTitle.text = jd["data"].dictionaryValue["title"]?.stringValue
                self.labelAddress.text = "来源：\(jd["data"].dictionaryValue["creator_name"]?.stringValue ?? "")"
                if jd["data"].dictionaryValue["attachment"]?.isEmpty == true {
                    self.btnFile.isHidden = true
                }else {
                    self.btnFile.isHidden = false
                    self.btnFile.accessibilityIdentifier = jd["data"].dictionaryValue["attachment"]?.dictionaryValue["download_url"]?.stringValue
                }                                
            }
        }
        
        // Do any additional setup after loading the view.
    }
    
    @IBAction func download(_ sender: UIButton) {
        
        Alamofire.request(try! (sender.accessibilityIdentifier?.asURL())!, method: .get, parameters: nil, encoding:URLEncoding.default , headers: nil).responseData { (data) in
            
        }
        
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
